package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo2 {
    public static void main(String[] args) {
        Map<String ,Integer> map=new HashMap<>();
        map.put("语文",85);
        map.put("数学",90);
        map.put("英语",100);
        map.put("物理",95);
        map.put("生物",76);
        map.put("化学",80);
        System.out.println(map);
        //遍历key
        Set<String> ks=map.keySet();
        for(String k:ks){
            System.out.println("key:"+k);
        }
        //遍历每一组键值对
        Set<Map.Entry<String,Integer>> es=map.entrySet();
        for(Map.Entry<String,Integer> e:es){
            String key=e.getKey();
            Integer value=e.getValue();
            System.out.println("key:"+key+" value:"+value);
        }
        //获取value值的集合
        Collection<Integer> vs=map.values();
        //遍历value
        for(Integer v:vs){
            System.out.println("value:"+v);
        }
        //遍历value
        vs.forEach(v-> System.out.println(v));
        vs.forEach(System.out::println);
        //遍历map
        map.forEach((k,v)->System.out.println("key:"+k+"，value："+v));

    }
}
